package edu.scau.mis.rest.service.impl;

import edu.scau.mis.rest.entity.RestFullDiscount;
import edu.scau.mis.rest.mapper.RestFullDiscountMapper;
import edu.scau.mis.rest.service.RestFullDiscountService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (RestFullDiscount)表服务实现类
 *
 * @author makejava
 * @since 2022-03-15 19:54:05
 */
@Service("restFullDiscountService")
public class RestFullDiscountServiceImpl implements RestFullDiscountService {
    @Resource
    private RestFullDiscountMapper restFullDiscountMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RestFullDiscount queryById(Long id) {
        return this.restFullDiscountMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param restFullDiscount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RestFullDiscount> queryByPage(RestFullDiscount restFullDiscount, PageRequest pageRequest) {
        long total = this.restFullDiscountMapper.count(restFullDiscount);
        return new PageImpl<>(this.restFullDiscountMapper.queryAllByLimit(restFullDiscount, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param restFullDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RestFullDiscount insert(RestFullDiscount restFullDiscount) {
        this.restFullDiscountMapper.insert(restFullDiscount);
        return restFullDiscount;
    }

    /**
     * 修改数据
     *
     * @param restFullDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RestFullDiscount update(RestFullDiscount restFullDiscount) {
        this.restFullDiscountMapper.update(restFullDiscount);
        return this.queryById(restFullDiscount.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.restFullDiscountMapper.deleteById(id) > 0;
    }
}
